package de.baumann.browser.present.duobao

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.duobao.CYJL
import de.baumann.browser.api.net.vo.duobao.DuoBao
import de.baumann.browser.api.net.vo.duobao.ZJXX
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.duobao.IJieXiaoDetailView
import de.baumann.browser.model.selectAnnounceInfo
import de.baumann.browser.model.selectAnnounceUserInfo
import de.baumann.browser.model.selectJoinList

class JieXiaoDetailPresenter : BasePresenter<IJieXiaoDetailView>() {
    fun detail() {
        selectAnnounceInfo(view!!.getId())
                .subscribe(object : OdinObserver<DuoBao>(view) {
                    override fun onSuccess(data: DuoBao?) {
                        if (data == null) {
                            return
                        }

                        val url = data.imageInfo
                        val list = if (url.contains(",")) {
                            url.split(",")
                        } else {
                            arrayListOf(url)
                        }
                        view?.setBanner(list)
                        view?.setTitle(data.title)
                        view?.setXYHM(data.winNum)
                        view?.setCYRS(data.joinNum.toString())
                        view?.setKJSJ(data.announceTime)
                        view.setZJMC(data.userName)
                        view.setZJTX(data.avatar)
                    }
                })
    }

    fun cyjl() {
        selectJoinList(view!!.getId())
                .subscribe(object : OdinObserver<List<CYJL>>(view) {
                    override fun onSuccess(data: List<CYJL>?) {
                        if (data == null) {
                            return
                        }
                        if (data.size > 2) {
                            view?.setList(data.subList(0, 2))
                        } else {
                            view.setList(data)
                        }
                    }
                })
    }


    fun zjxx() {
        selectAnnounceUserInfo(view!!.getId())
                .subscribe(object : OdinObserver<ZJXX>(view) {
                    override fun onSuccess(data: ZJXX?) {
                        if (data != null)
                            view?.setZJXX(data)
                    }
                })
    }

}